package com.hbt.english.controller;

import com.hbt.api.entity.CommonResult;
import com.hbt.api.entity.User;
import com.hbt.english.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user_provider")
public class UserProviderController {
    @Autowired
    UserService userService;
//    @Value("${img_path}")
//    String img_path;

    @RequestMapping("test")
    public String test(){
        return "test success";
    }

    @PostMapping("uploadAvatar")
    public CommonResult uploadAvatar(@RequestBody MultipartFile file, String token) throws IOException {

        System.out.println("userprovider uploadAvatar start**********************");
        if (file!=null){
            System.out.println("file != null");
            System.out.println("文件名"+file.getOriginalFilename());
        }else{
            System.out.println("file == null");
        }
        if (token!=null){
            System.out.println("token != null:"+token);
        }else{
            System.out.println("token == null");
        }
        System.out.println("userprovider uploadAvatar end********and after will upload file");
        return userService.uploadAvatar(file, token);
    }

    @PostMapping("getUserByToken")
    public CommonResult getUserByToken(@RequestBody String token){

        return userService.getUserByToken(token);
    }


    @RequestMapping(value = "dologin", method = RequestMethod.POST)
    public CommonResult dologin(@RequestBody User user) {
        //日志打印
        System.out.println("enter user provider controller dologin");
        System.out.println("user:"+user);
        return userService.dologin(user);
    }
}
